package com.base.controller;

import com.base.po.voip.UsersReleaseConfig;
import com.base.service.LogsService;
import com.base.service.UsersReleaseConfigService;
import com.base.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 账户释放比例配置信息 修改
 * 
 * @author f 优化日期：10-11
 *
 */
@Controller
@RequestMapping("/admin")
public class ReleaseConfigUpdateController {

	@Autowired
	private LogsService logsService; // 日志Service
	@Autowired
	private UsersService usersService; // 账户信息Service
	@Autowired
	private UsersReleaseConfigService usersReleaseConfigService;

	// 账户信息 修改
	@RequestMapping(value = "/release_config_do_update", method = RequestMethod.POST)
	public @ResponseBody int doReleaseUpdate(HttpServletRequest request, @RequestBody UsersReleaseConfig releaseConfig) {
		HttpSession session = request.getSession(false); // 获取session
		if (session == null) {
			return -1;
		}
		Object obj_id = session.getAttribute("adminUserId"); // 登录ID
		Object obj_name = session.getAttribute("userNick"); // 登录名称
		if (obj_id == null || obj_name == null) {
			return -1;
		}

		if (releaseConfig.getId() != null){
			return usersReleaseConfigService.updateByPrimaryKeySelective(releaseConfig); // 修改
		}else {
			releaseConfig.setParentId(obj_id.toString());
			return usersReleaseConfigService.insertSelective(releaseConfig); // 插入
		}
	}
}
